package org.sibframework.sda;

import java.sql.SQLException;

public class SdaFactory {

	static SimpleDataAccess instance;
	
	/**
	 * get singleton instance
	 * 得到当前在使用的sda对象, 符合单态模式, 减少对象和链接的反复创建和关闭, 提高系统速度和效率.
	 * @return instance
	 * @throws Exception 
	 */
	public synchronized static SimpleDataAccess getInstance() throws SQLException {
		if (instance == null || instance.isClosed()) {
			instance = new SimpleDataAccess();
		}  else {
			instance.checkConnection();
		}
		
		return instance;
	}
	

	
	
	/**
	 * start a new SDA 。 开始一个新sda， 注意：一定要及时关闭。
	 * 
	 * @return save point object to roll back;
	 * @throws Exception
	 */
	public synchronized SimpleDataAccess createInstance() throws SQLException {
		return new SimpleDataAccess();
	}
}
